$(document).ready(function() {
	countNewMessage();
	setInterval(function(){
		countNewMessage();
	}, 3000);
	$("#toggleMenu").click(function(){ $("#menuToToggle").toggle(200); });
	
	var resizedWindow = $(window).resize(function(e) {
		var windowWidth = $(window).width();
		if(windowWidth <= 768)
		{
			$("#menuToToggle").css({
				'display':'none'	
			});
		}
		else
		{
			$("#menuToToggle").css({
				'display':'block'	
			});
		}
    });
	
	var getRefreshWidth = $(window).width();
	if(getRefreshWidth <= 768)
	{
		$("#menuToToggle").css({
			'display':'none'	
		});
	}
	else
	{
		$("#menuToToggle").css({
			'display':'block'
		});
	}
	
	$('.getRestoLocation').click(function(event){
		event.preventDefault();
		var getLat = $(this).attr('data-lat');
		var getLng = $(this).attr('data-lng');
		var restoDetails = $(this).attr('data-details');
		var restoLocation = $(this).attr('data-role');
		$(".overlayHolder").fadeToggle("fast");
		var getIDContent = $(this).attr('data-id');
		var getDataContent = $(this).attr('data-title');
		var getDataLocation = $(this).attr('data-role');
		$('.boxOverlayContent').css({
			'width' : '60%'
		});
		overlayPopUp = '';
		overlayPopUp += '<div class="popUpHolder">';
			overlayPopUp += '<div class="headerPopUp"><i class="icon-map-marker icon-white"></i> Location of <strong>'+getDataContent+'</strong>';
				overlayPopUp += '<div class="closeHolder closeOverlay"><i class="icon-remove icon-white"></i></div>';
			overlayPopUp += '</div>';
			overlayPopUp += '<div class="popUpContent">';
				overlayPopUp += '<div class="mapContainer"><div id="map-canvas"></div></div>';
			overlayPopUp += '</div>';
			overlayPopUp += '<i class="clearfix"></i>';
			overlayPopUp += '<div class="popUpFooHolder">';
				overlayPopUp += '<div class="foo">';
					overlayPopUp += getDataLocation;
				overlayPopUp += '</div>';
			overlayPopUp += '</div>';
		overlayPopUp += '</div>';
		$('.boxOverlayContent').html(overlayPopUp);
		$('.closeOverlay').click(function(){
			$(".overlayHolder").hide();
		});
		initializeMap(getLat, getLng, restoDetails, restoLocation);
	});
	$('#doRegister1, #doRegister2').click(function(event){
		event.preventDefault();
		$(".overlayHolder").fadeToggle("fast");
		$('.boxOverlayContent').css({
			'width' : '30%',
			'min-width' : '300px',
			'box-shadow': 'none'
		});
		overlayPopUp = '';
		overlayPopUp += '<div class="popUpHolder">';
			overlayPopUp += '<div class="headerPopUp"><i class="icon-map-marker icon-white"></i><strong>Signup</strong>';
				overlayPopUp += '<div class="closeHolder closeOverlay"><i class="icon-remove icon-white"></i></div>';
			overlayPopUp += '</div>';
			overlayPopUp += '<div class="popUpContent" style="background:url('+base_url+'assets/img/front_assets/reg_bg.png) no-repeat;background-position:80px -53px">';
				overlayPopUp += '<div class="mapContainer">';
					overlayPopUp += '<table style="margin-left:5px;">';
						overlayPopUp += '<tbody>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td style="color:#bb1616"><strong>Already have an account? <a style="color:#bb1616;font-size:14px;" href="'+base_url+'home">Login.</a></strong></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td style="color:#bb1616"><strong>Firstname</strong></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td><input type="text" id="strFirstName" style="border: 1px solid #bb1616" /></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td style="color:#bb1616"><strong>Lastname</strong></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td><input type="text" id="strLastName" style="border: 1px solid #bb1616" /></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td style="color:#bb1616"><strong>Email</strong></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td><input type="text" id="strEmail" style="border: 1px solid #bb1616" /></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td style="color:#bb1616"><strong>Contact Number</strong></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td><input type="text" id="strContactNumber" style="border: 1px solid #bb1616" /></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td style="color:#bb1616"><strong>Password</strong></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td><input type="password" id="strPassword" style="border: 1px solid #bb1616" /></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td style="color:#bb1616"><label for="strSendMeEmail" style="font-size:11.5px"><input type="checkbox" id="strSendMeEmail" style="float:left" /> <strong style="margin-left:5px;float:left">Email Newsletter</strong></label></td>';
							overlayPopUp += '</tr>';
							overlayPopUp += '<div class="clearfix"></div>';
							overlayPopUp += '<tr>';
								overlayPopUp += '<td style="color:#bb1616"><label for="tor" style="font-size:11.5px"><input type="checkbox" id="tor" style="float:left"><strong style="margin-left:5px;float:left">Accept Terms and Conditions</strong></label></td>';
							overlayPopUp += '</tr>';
						overlayPopUp += '</tbody>';
					overlayPopUp += '</table>';
				overlayPopUp += '</div>';
			overlayPopUp += '</div>';
			overlayPopUp += '<i class="clearfix"></i>';
			overlayPopUp += '<div class="popUpFooHolder" style="background:#bb1616;margin-top:0; border-top:0;height:25px;text-align:right">';
				overlayPopUp += '<div class="foo">';
					overlayPopUp += '<span style="float:left" id="msg"></span><button class="btn btn-small" style="float:right" id="submitRegister"><i class="icon-ok-circle"></i> Submit</button>';
				overlayPopUp += '</div>';
			overlayPopUp += '</div>';
		overlayPopUp += '</div>';
		$('.boxOverlayContent').html(overlayPopUp);
		$('#submitRegister').click(function(){
			doRegister();
		});
		$('.closeOverlay').click(function(){
			$(".overlayHolder").hide();
		});
	});
});
function doRegister()
{
	var strFirstName = $('#strFirstName').val();
	var strLastName = $('#strLastName').val();
	var strEmail = $('#strEmail').val();
	var strContactNumber = $('#strContactNumber').val();
	var strPassword = $('#strPassword').val();
	var strSendMeEmail = $('#strSendMeEmail').is(':checked');
	var tor = $('#tor').is(':checked');
	
	if(strFirstName == '')
	{
		$('#msg').html('<div class="alert alert-error" style="height:19px;padding:3px 10px;margin:0;border:0;">Put your firstname</div>');
	}
	else if(strLastName == '')
	{
		$('#msg').html('<div class="alert alert-error" style="height:19px;padding:3px 10px;margin:0;border:0;">Put your lastname</div>');
	}
	else if(strEmail == '')
	{
		$('#msg').html('<div class="alert alert-error" style="height:19px;padding:3px 10px;margin:0;border:0;">Put your email</div>');
	}
	else if(strContactNumber == '')
	{
		$('#msg').html('<div class="alert alert-error" style="height:19px;padding:3px 10px;margin:0;border:0;">Put your contact number</div>');
	}
	else if(strPassword == '')
	{
		$('#msg').html('<div class="alert alert-error" style="height:19px;padding:3px 10px;margin:0;border:0;">Put your password</div>');
	}
	else if(tor == false)
	{
		$('#msg').html('<div class="alert alert-error" style="height:19px;padding:3px 10px;margin:0;border:0;">You need to accept the terms and condition</div>');
	}
	else
	{
		$('#submitRegister').text('Processing...');
		setTimeout(function(){
			uri = 'main/reserve_resto';
			data = {
				'strFirstName':strFirstName,
				'strLastName':strLastName,
				'strEmail':strEmail,
				'strContactNumber':strContactNumber,
				'strPassword':strPassword
			};
			$.ajax({
				type: "POST",
				url: base_url+uri,
				data: data,
				dataType: 'json',
				success: function(result){
					if(result.intStatus=='1')
					{
						$('.mapContainer').css({
							'height' : '361px'
						});
						msgContent = '';
						msgContent += '<div style="text-align:center">';
							msgContent += '<strong>You successfully send an inquiry.</strong>';
							msgContent += '<p>We will send you a message if your account is ready.</p>';
							msgContent += '<br/><br/>';
							msgContent += 'Thank you.';
						msgContent += '</div>';
						$('#submitRegister').hide();
						$('.mapContainer').html(msgContent);
					}
					else
					{
						$('#msg').html('<div class="alert alert-error" style="height:19px;padding:3px 10px;margin:0;border:0;">Error: Please try again later.</div>');
					}
				}
			});
		}, 3000);
	}
}
function initializeMap(getLat, getLng, restoDetails, restoLocation)
{
	var myLatLng = new google.maps.LatLng(getLat, getLng);
	var mapOptions = {
	  center: myLatLng,
	  zoom: 14,
      zoomControl: false,
	  panControl: false,
	  mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
	var contentString = '<div style="width:300px !important;" id="content">'+
						'<div id="siteNotice"></div>'+
						'<h4 id="firstHeading" class="firstHeading">'+restoDetails+'</h4>'+
						'<div id="bodyContent">'+
						'<p>'+restoLocation+'</p>'+
						'</div>'+
						'</div>';
	
	var infowindow = new google.maps.InfoWindow({
							content: contentString
					});
	var marker = new google.maps.Marker({
	  position: myLatLng,
	  map: map,
	  title: restoDetails,
	});
	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(map, marker);
	});
}
function doGetLocation(intRestoID){
	/*uri = 'dashboard/delete_resto';
	data = {
		'intRestoID':intRestoID	
	};
	$.ajax({
		type: "POST",
		url: base_url+uri,
		data: data,
		dataType: 'json',
		success: function(result){
			var getItemID = $('.doDeleteThis').attr('data-id');
			
			$('#item_'+getItemID).remove('#item_'+getItemID);
			$(".overlayHolder").hide();
		}
	});*/
}